package com.moon.game.command.guest.sys;

import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.constants.ErrorCode;
import com.moon.game.exception.GException;
import com.moon.game.manager.NoticeMG;
import com.moon.game.resource.model.Notice;
import com.moon.game.vos.ErrorMsg;

/**
 * @description 查看指定公告详细信息
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-7-25 下午4:32:36
 */
public class ShowNoticeDetailCmd extends BaseCmd {

	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
			case STATU_INIT:
				doInit(req);
				break;
			case STATU_CHECK:
				doCheckSelf(req);
				break;
			case STATU_RETURN:
				doResponse(req);
				break;
			default:
				break;
		}
	}

	@Override
	protected void doResponse(RequestSession req) throws GException {
		String[] ps = req.getClientRequest().getPs();
		if (ps == null) {
			doResponsePsError(req);
			return;
		}
		Integer id = Integer.parseInt(ps[0]);
		if (id == null) {
			doResponsePsError(req);
			return;
		}
		@SuppressWarnings("static-access")
		Notice notice = NoticeMG.instance.getTheNotice(id);
		if (notice == null) {
			doResponseErrorMsg(req, ErrorMsg.build(ErrorCode.ERR_SYS, "没有你要查看的公告！"));
			return;
		}
		req.setVO("name", notice.getName());
		req.setVO("content", notice.getContent());
		response(req, req.getClientResponse());
	}

}
